package com.har.modules.web.controller;

import com.har.common.exception.RRException;
import com.har.common.utils.R;
import com.har.common.utils.ValidatUtil;
import com.har.common.utils.ValidatorUtils;
import com.har.modules.web.entity.SuggesionEntity;
import com.har.modules.web.service.SuggesionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 意见表
 *
 * @author maorui
 *
 */
@RestController
@RequestMapping("/suggesion")
public class SuggesionController {
    @Autowired
    private SuggesionService suggesionService;


    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SuggesionEntity suggesion){
        ValidatorUtils.validateEntity(suggesion);
        if(!ValidatUtil.checkMobileNumber(suggesion.getMobile().toString())){
            throw new RRException("手机号码格式不正确");
        }
        suggesion.setCreateTime(new Date());
        suggesionService.insert(suggesion);

        return R.ok();
    }


}
